package view.backend.product;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JLabel;
import model.ProductFamily;
import view.generaldesign.DesignLayout;

/**
 *
 * @author Sonny Sandberg
 */
public class AdminProductFamilySearchLabel extends JLabel
{
    private ProductFamily productFamily;
    private AdminProduct adminProduct;

    public AdminProductFamilySearchLabel(ProductFamily model, AdminProduct view)
    {
        this.productFamily = model;
        this.adminProduct = view;
        
        setBounds(1, 1, 118, 20);
        setFont(DesignLayout.STANDARD.deriveFont(12f));
        setOpaque(true);
        setBackground(DesignLayout.T_FIELD_BG_COLOR);
        setText(model.getName());
        
        MouseAdapter mouseReleased;
        mouseReleased =
                (
                    new MouseAdapter()
                    {
                        public void mouseReleased(MouseEvent evt)
                        {
                            adminProduct.getAdminNewProduct().setProductFamilyField(productFamily.getName());
                            adminProduct.getProductModel().setProductFamily(productFamily);
                            adminProduct.getAdminNewProduct().setProductFamilySearchPanelVisibility(false);
                            adminProduct.getAdminNewProductOverview().updateLabelsFromModel();
                        }
                    }
                );
        
        this.addMouseListener(mouseReleased);
    }
}